ÄúµÄλÖãºÑ°ÃÎÍøÊ×Ò³£¾±à³ÌÀÖÔ°£¾VBScript£¾VBScript


objects constants operators statements functions properties methods







OBJECT:  Dictionary

CreateObject("Scripting.Dictionary")

The Dictionary object stores name/value pairs (referred to as the key and item respectively) in an array. The key is a unique identifier for the corresponding item and cannot be used for any other item in the same Dictionary object.

The following code creates a Dictionary object called "cars", adds some key/item pairs, retrieves the item value for the key 'b' using the Item property and then outputs the resulting string to the browser.

Code:
<%
Dim cars
Set cars = CreateObject("Scripting.Dictionary")
cars.Add "a", "Alvis"
cars.Add "b", "Buick"
cars.Add "c", "Cadillac"
Response.Write "The value corresponding to the key 'b' is " cars.Item("b")
%>

Output:
"The value corresponding to the key 'b' is Buick"

METHODS

Add Method
The Add method is used to add a new key/item pair to a Dictionary object.

Syntax: object.Add keyvalue, itemvalue

Exists Method
The Exists method is used to determine whether a key already exists in the specified Dictionary. Returns True if it does and False otherwise.

Syntax: object.Exists(keyvalue)

Items Method
The Items method is used to retreive all of the items in a particular Dictionary object and store them in an array.

Syntax: [arrayname = ]object.Items

Keys Method
The Keys method is used to retreive all of the keys in a particular Dictionary object and store them in an array.

Syntax: [arrayname = ]object.Keys

Remove Method
The Remove method is used to remove a single key/item pair from the specified Dictionary object.

Syntax: object.Remove (keyvalue)

RemoveAll Method
The RemoveAll method is used to remove all the key/item pairs from the specified Dictionary object.

Syntax: object.RemoveAll


PROPERTIES

CompareMode Property
The CompareMode property is used to set and return the key's string comparison mode which determines how keys are matched while looking up or searching.

Syntax: object.CompareMode[ = comparison_mode]

Count Property
The Count property is used to determine the number of key/item pairs in the Dictionary object.

Syntax: object.Count

Item Property
The Item property allows us to retreive the value of an item for a specified key and also to change that value when using the optional itemvalue argument.

Syntax: object.Item(keyvalue) [ = itemvalue]

Key Property
The Key property lets us change the key value of an existing key/item pair.

Syntax: object.Key(keyvalue) = newkeyvalue